import * as API from '../axios'
import * as util from "@/common/util";
import Vue from "vue";
import store from "@/store/store";
export default {

  //获取总后台-系统配置
  getPlatformConfigs: params => {
    return API.axiosGetAPI('/manage/sys-configs/obm', params)
  },
  //系统配置-列表
  getConfigs: params => {
    return new Promise((resolve, reject) => {
      API.axiosGetAPI('/manage/sys-configs', params).then(res => {
        if (Vue.prototype.$ok(res)) {
          // 查询全部时进行数据缓存
          if (!params || params === undefined || params === null) {
            // list转map,便于各个页面直接获取配置项
            if (res.data && res.data.length > 0) {
              store.commit('SET_XT', res.data)
              res.data = store.state.xt
            }
          }
        }
        resolve(res)
      }).catch(res => {
        reject(res)
      })
    })
  },
  //系统配置-修改
  modifyConfigs: params => {
    const headers = {
      'lang-key': 'branch_Edit'
    }
    return API.axiosPutAPI('/manage/sys-configs', params, headers)
  },
  //系统配置-批量修改
  batchModifyConfigs: params => {
    const headers = {
      'lang-key': 'branch_Edit'
    }
    return API.axiosPutAPI('/manage/sys-configs/batch', params, headers)
  },


  Importcabinets: params => {
    return API.axiosPostAPI('/manage/excel', params)
  },


  // 获取操作日志
  getPageForOperationLog: (params, page) => {
    const url = util.replacePageNumAndSize('/manage/operation-logs/{pageNum}/{pageSize}', page)
    return API.axiosGetAPI(url, params)
  },

  //计费规则下拉
  getBillingOption: params => {
    return API.axiosGetAPI('/manage/billings/all', params)
  },

  //计费规则编辑
  editRules: (id, billingId) => {
    const headers = {
      'lang-key': 'branch_Edit'
    }
    return API.axiosPutAPI(`/manage/branches/${id}/billing/${billingId}`, '', headers)
  },


  // 系统配置-获取租借条件设置
  getRentalSetting: params => {
    return API.axiosGetAPI('/manage/sys-configs/rental-terms', params)
  },

  // 系统配置-编辑租借条件设置
  setRentalSetting: params => {
    const headers = {
      'lang-key': 'branch_Edit'
    }
    return API.axiosPutAPI('/manage/sys-configs/rental-terms', params, headers)
  },

  // 系统配置-获取税率设置
  getTaxSetting: () => {
    return API.axiosGetAPI('/manage/sys-configs/tax-setting')
  },

  // 系统配置-编辑税率设置
  setTaxSetting: (params) => {
    const headers = {
      'lang-key': 'branch_Edit'
    }
    return API.axiosPutAPI('/manage/sys-configs/tax-setting',params, headers)
  }    

}